package com.luych.toolbox.common.page;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

@ApiModel("分页查询结果")
public class CommonPageResult<T> implements PageResult<T> {

    @ApiModelProperty("查询结果列表")
    private List<T> records;
    @ApiModelProperty("总行数")
    private long total;

    public CommonPageResult() {
    }

    public CommonPageResult(List<T> records, long total) {
        this.records = records;
        this.total = total;
    }

    public static <T> CommonPageResult<T> getInstance(PageResult<T> pageResult) {
        return new CommonPageResult<>(pageResult.getRecords(), pageResult.getTotal());
    }

    public static <T> CommonPageResult<T> getInstance() {
        return new CommonPageResult<T>();
    }

    @Override
    public List<T> getRecords() {
        return records;
    }

    public CommonPageResult setRecords(List<T> records) {
        this.records = records;
        return this;
    }

    @Override
    public long getTotal() {
        return total;
    }

    public CommonPageResult setTotal(long total) {
        this.total = total;
        return this;
    }
}
